//
//  QPointsDatesView.m
//  QoilPublic
//
//  Created by 杨凯 on 2017/3/19.
//  Copyright © 2017年 杨凯. All rights reserved.
//

#import "QPointsDatesView.h"
#import "QPointsDatesCell.h"
#import "QPointDaysModel.h"
@interface QPointsDatesView ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
    UICollectionView *collection;
}

@end
@implementation QPointsDatesView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){
        [self setUpUI];
    }
    return self;
    
}

- (void)setListModel:(QPointInfoListModel *)listModel{
    _listModel = listModel;
    [collection reloadData];
}

-(void)awakeFromNib
{
    [super awakeFromNib];
    [self setUpUI];
}
-(void)setUpUI
{
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    
    collection=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 5, kScreenWidth, 90) collectionViewLayout:layout];
    collection.backgroundColor=[UIColor whiteColor];
    collection.showsHorizontalScrollIndicator=NO;
    collection.pagingEnabled = YES;
    collection.delegate = self;
    collection.dataSource = self;
    
    [collection registerNib:[UINib nibWithNibName:@"QPointsDatesCell" bundle:nil] forCellWithReuseIdentifier:@"QPointsDatesCell"];
    [self addSubview:collection];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _listModel.list.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    QPointsDatesCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QPointsDatesCell" forIndexPath:indexPath];
    QPointDaysModel * model = _listModel.list [indexPath.row];
    cell.pointLab.hidden = (indexPath.row == self.listModel.list.count-1)?YES:NO;
    cell.roundLab.text = [NSString stringWithFormat:@"+%@",model.day_integration];
    
    
    if (indexPath.row == 0) {
        cell.dateLab.text =@"昨天";

        if ([model.sign_status isEqualToString:@"1"]) {
            cell.roundLab.backgroundColor = [UIColor whiteColor];
            cell.roundLab.textColor = [QColorUtility defaultLowGrayColor];
            cell.pointLab.backgroundColor = [QColorUtility defaultLowGrayColor];
        }else{
            cell.roundLab.backgroundColor = [QColorUtility defaultLowGrayColor];
            cell.roundLab.textColor = [UIColor whiteColor];
            cell.pointLab.backgroundColor = [QColorUtility defaultMainColor];

        }
    }else if (indexPath.row == 1){
        cell.dateLab.text =@"今天";

        if ([model.sign_status isEqualToString:@"1"]) {
            
        }else{
            cell.roundLab.layer.borderColor = [QColorUtility defaultMainColor].CGColor;
            cell.roundLab.textColor = [QColorUtility defaultMainColor];
            cell.pointLab.backgroundColor = [QColorUtility defaultMainColor];
        }
    }else{
        if (![model.select_day isEqualToString:@""]) {
            cell.dateLab.text =[[model.select_day substringWithRange:NSMakeRange(5, 5)] stringByReplacingOccurrencesOfString:@"-" withString:@"."];
        }
        cell.roundLab.backgroundColor = [UIColor whiteColor];
        cell.roundLab.layer.borderColor = [QColorUtility defaultLowGrayColor].CGColor;
        cell.roundLab.textColor = [QColorUtility defaultLowGrayColor];
        cell.pointLab.backgroundColor = [QColorUtility defaultLowGrayColor];


    }
    return cell;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 5, 0, 0);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(60, 85);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 5.0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 5.0;
}

@end
